package errorcode

import (
	"net/http"
	"sugar/response"

	"github.com/gin-gonic/gin"
)

type Error struct {
	response.Response
}

func OtherError(message string) *Error {
	return NewError(http.StatusForbidden, 100403, message)
}

func (e *Error) Error() string {
	return e.Msg
}

func NewError(statusCode, Code int, msg string) *Error {
	return &Error{
		Response: response.Response{
			StatusCode: statusCode,
			Code:       Code,
			Msg:        msg,
			Data:       nil,
		},
	}
}

// 404处理
func HandleNotFound(c *gin.Context) {
	err := NotFound
	c.JSON(err.StatusCode, err)
	return
}

var (
	// Success     = NewError(http.StatusOK, 0, "success")
	ServerError               = NewError(http.StatusInternalServerError, 200500, "Server Error")
	NotFound                  = NewError(http.StatusNotFound, 200404, http.StatusText(http.StatusNotFound))
	TokenError                = NewError(http.StatusUnauthorized, 200801, "Token Error")
	ParamError                = NewError(http.StatusInternalServerError, 200802, "Param Error")
	MkdirError                = NewError(http.StatusInternalServerError, 200802, "Mkdir Error")
	NetPortError              = NewError(http.StatusInternalServerError, 200802, "Net Port Error")
	FileOperationError        = NewError(http.StatusInternalServerError, 200802, "File Operation Error")
	JSONOperationError        = NewError(http.StatusInternalServerError, 200803, "Json Operation Error")
	KubernetesOperationError  = NewError(http.StatusInternalServerError, 200803, "Kubernetes Operation Error")
	SendEmailError            = NewError(http.StatusInternalServerError, 200901, "Send Email Error")
	CacheOperationError       = NewError(http.StatusInternalServerError, 200902, "Cache Operation Error")
	TooFrequentError          = NewError(http.StatusInternalServerError, 200902, "Operate Too Frequently. Retry After Waiting For Some Seconds")
	ValidateCodeNotMatchError = NewError(http.StatusInternalServerError, 200903, "Validate Code Not Match Error")
	ValidateCodeExpiredError  = NewError(http.StatusInternalServerError, 200903, "Validate Code Expired Error")
	LoadPrivateKeyError       = NewError(http.StatusInternalServerError, 200904, "Load Private Key Error")
	DecryptError              = NewError(http.StatusInternalServerError, 200905, "Decrypt Error")
	GeneratePasswordHashError = NewError(http.StatusInternalServerError, 200906, "Generate Password Hash Error")
	UserAlreadyExistError     = NewError(http.StatusInternalServerError, 200907, "User Already Exist Error")
	UserNotExistError         = NewError(http.StatusInternalServerError, 200908, "User Not Exist Error")
	UserAlreadyBanned         = NewError(http.StatusInternalServerError, 200909, "User Already Banned Error")
	PasswordNotMatch          = NewError(http.StatusInternalServerError, 200910, "Password Not Match Error")
	CreateUserError           = NewError(http.StatusInternalServerError, 200918, "Create User Error")
	ResetPasswordError        = NewError(http.StatusInternalServerError, 200919, "Reset Password Error")
	ResetEmailError           = NewError(http.StatusInternalServerError, 200920, "Reset Email Error")
	UpdateUserInfoError       = NewError(http.StatusInternalServerError, 200921, "Update User Info Error")
	ListDatasetError          = NewError(http.StatusInternalServerError, 200925, "List Dataset Error")
	GetDatasetError           = NewError(http.StatusInternalServerError, 200926, "Get Dataset Error Or Dataset Not Exist")
	NoDatasetAuthError        = NewError(http.StatusInternalServerError, 200927, "No Dataset Auth Error")
	CreateDatasetError        = NewError(http.StatusInternalServerError, 200928, "Create Dataset Error")
	DatasetAlreadyExistError  = NewError(http.StatusInternalServerError, 200929, "Dataset Already Exist Error")

	ListModelError         = NewError(http.StatusInternalServerError, 200950, "List Model Error")
	GetModelError          = NewError(http.StatusInternalServerError, 200951, "Get Model Error")
	CreateModelError       = NewError(http.StatusInternalServerError, 200952, "Create Model Error")
	ModelAlreadyExistError = NewError(http.StatusInternalServerError, 200953, "Model Already Exist Error")

	ListTrainJobError         = NewError(http.StatusInternalServerError, 200970, "List Train Job Error")
	CreateTrainJobError       = NewError(http.StatusInternalServerError, 200971, "Create Train Job Error")
	DeleteTrainJobError       = NewError(http.StatusInternalServerError, 200972, "Delete Train Job Error")
	GetTrainJobError          = NewError(http.StatusInternalServerError, 200973, "Get Train Job Error")
	NoTrainJobAuthError       = NewError(http.StatusInternalServerError, 200974, "No Train Job Auth Error")
	TrainJobNotSuccessError   = NewError(http.StatusInternalServerError, 200975, "Train Job Not Success Error")
	TrainJobAlreadyExistError = NewError(http.StatusInternalServerError, 200976, "Train Job Already Exist Error")
	TypeNotMatchError         = NewError(http.StatusInternalServerError, 200977, "Type Not Match Error")
	UpdateTrainJobStatusError = NewError(http.StatusInternalServerError, 200978, "Update Train Job Status Error")

	ListAppError         = NewError(http.StatusInternalServerError, 200990, "List App Error")
	CreateAppError       = NewError(http.StatusInternalServerError, 200991, "Create App Error")
	DeleteAppError       = NewError(http.StatusInternalServerError, 200992, "Delete App Error")
	GetAppError          = NewError(http.StatusInternalServerError, 200993, "Get App Error")
	NoAppAuthError       = NewError(http.StatusInternalServerError, 200994, "No App Auth Error")
	AppAlreadyExistError = NewError(http.StatusInternalServerError, 200995, "App Already Exist Error")
	UpdateAppStatusError = NewError(http.StatusInternalServerError, 200996, "Update App Status Error")
)
